package vn.edu.saigontech.ncms.web.program;

import vn.edu.saigontech.ncms.model.info.Student;
import vn.edu.saigontech.ncms.model.info.Waiting;
import vn.edu.saigontech.ncms.model.program.Level;
import vn.edu.saigontech.ncms.service.LevelService;
import vn.edu.saigontech.ncms.service.StudentService;
import vn.edu.saigontech.ncms.service.WaitingService;
import vn.edu.saigontech.ncms.util.Checker;
import vn.edu.saigontech.ncms.web.AbstractValidator;

@SuppressWarnings("serial")
public class ValidateWaitingAction extends AbstractValidator {
	
	private Long id;
	private Long levelId;
	private Long studentId;
	private String registeredDate;

	public String check() {
		if(Checker.isNull(this.levelId)) {
			this.sendKeyError("validator.required", "level");
		}
		if(Checker.isEmpty(this.registeredDate)) {
			this.sendKeyError("validator.required", "registeredDate");
		}
		if(!Checker.isDate(this.registeredDate, this.i18n("format.date"))) {
			this.sendKeyError("validator.mask", "registeredDate", "format.date");
		}
		Level level = LevelService.INSTANCE.findById(this.levelId);
		Student student = StudentService.INSTANCE.findById(this.studentId);
		Waiting existed = WaitingService.INSTANCE.findById(this.id);
		
		Waiting waiting = new Waiting();
		waiting.setStudent(student);
		if(level.contains(waiting) && Checker.isNull(existed)) {
			this.sendKeyError("validator.exist", "student");
		}
		return this.toSuccess();
	}
	
	public Long getLevelId() {
		return levelId;
	}

	public void setLevelId(Long levelId) {
		this.levelId = levelId;
	}

	public Long getStudentId() {
		return studentId;
	}

	public void setStudentId(Long studentId) {
		this.studentId = studentId;
	}

	public String getRegisteredDate() {
		return registeredDate;
	}

	public void setRegisteredDate(String registeredDate) {
		this.registeredDate = registeredDate;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
}
